if (typeof(TMR_STATUS_UPDATE_INTERVAL) == 'undefined') TMR_STATUS_UPDATE_INTERVAL = 30;
if (typeof(TMR_DEFAULT_IMAGE) == 'undefined') TMR_DEFAULT_IMAGE = 'http://tmrweb.ikito.ru/images/music.jpg';
TMR_FORCE_STATUS_UPDATE = false;

// Loads JS file
function load_cdt_js() {
    var script = document.createElement('script');
    script.type = "text/javascript";
    script.src = 'http://tmrweb.ikito.ru/js/cdt/crossdomain-tools.js';
    document.getElementsByTagName("head")[0].appendChild(script);
};

function draw_tm_status_widget() {
    if (document.getElementById('tmr_status_container')) return;
    var widget_html = ' \
<div id="tmr_status_container"> \
    <div class="tmr_image" id="tmr_image"></div> \
    <div id="tmr_status_block"> \
        Сейчас на радио: <span id="tm_status_text">подождите подождите...</span> \
    </div> \
    <div id="tmr_track_info"></div> \
    <div id="tmr_download_link"></div> \
</div> \
    ';
    document.write(widget_html);
}

function init_widget() {
    console.log('Initializing status widget');
    console.log('Widget HTML added');
    cdt_load_css("http://tmrweb.ikito.ru/css/status_info.css");
    cdt_load_js("http://tmrweb.ikito.ru/js/status_info/status_info_core.js");
    console.log('Widget core JavaScript loaded');
};

function status_info_core_loaded() {
    TMR_UPDATE_TIMER = window.setInterval(call_tmr_status_update, TMR_STATUS_UPDATE_INTERVAL * 1000);
    call_tmr_status_update();
};

draw_tm_status_widget();

if (typeof(cdt_load_css) == 'undefined') {
    console.log('Crossdomain tools not loaded, loading.');
    cdt_tools_loaded = init_widget;
    load_cdt_js();
} else {
    init_widget();
};